/*============================================================================*/
/*       UNIVERSIDAD DE GUADALAJARA - CONTINENTAL AUTOMOTIVE SYSTEMS          */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* %name:            %
* %version:         %
* %created_by:      %
* %date_created:    %
*=============================================================================*/
/* DESCRIPTION : Timers handling                                              */
/*============================================================================*/
/* FUNCTION COMMENT : Provices APIs to configure and use Timers of PIC micro  */
/*                                                                            */
/*                                                                            */
/*============================================================================*/
#include "stdtypedef.h"
#include "p18f4550.h"
#include "cpu_drv.h"
#include "mw_schm_cfg.h"
#include "mw_schm.h"
#include "prjt_config.h"
void initializeADC(void)
{OSCCONbits.SCS0 = 0;
    OSCCONbits.SCS1 = 1; 
    OSCCONbits.IRCF0 = 1;
    OSCCONbits.IRCF1 = 1;
    OSCCONbits.IRCF2 = 1;

    OSCCONbits.IDLEN = 0;

//ADCON0 CONFIGURATION
	//Select channel 0 CHS3:CHS0 -> 0000
	ADCON0bits.CHS3=0;
	ADCON0bits.CHS2=0;
	ADCON0bits.CHS1=0;
	ADCON0bits.CHS0=0;
	//Enable ADC
	ADCON0bits.ADON=1;	

	//ADCON1 CONFIGURATION
	ADCON1bits.VCFG1=0; //use VSS as - reference
	ADCON1bits.VCFG0=0;	//use VDD as + reference
	ADCON1bits.PCFG3=1;
	ADCON1bits.PCFG2=1;
	ADCON1bits.PCFG1=1;
	ADCON1bits.PCFG0=0;

	//ADCON2 CONFIGURATION
	ADCON2bits.ADFM=0;
	//Select 2TAD
	ADCON2bits.ACQT2=0;
	ADCON2bits.ACQT1=0;
	ADCON2bits.ACQT0=0;
	//select FRC (clock derived from A/D RC oscillator)
	ADCON2bits.ADCS2=0;
	ADCON2bits.ADCS1=0;
	ADCON2bits.ADCS0=0;
    //configure pin 2 as input
	//TRISAbits.TRISA0=1;
    
	TRISD=0X00;
	TRISB=0X00;
	LATB=0;
	TRISCbits.TRISC0=1;
	TRISCbits.TRISC1=1;
	TRISCbits.TRISC6=1;
	TRISCbits.TRISC7=0;
	TRISAbits.TRISA6=0;
	LATAbits.LATA6=1;

//interrupts
INTCONbits.GIE=0;//global interrupts enables
//INTCONbits.INT0IE1=0;//external interrupt 0 enabled
//INTCON2bits.INTEDG0=0;//int0 triggers on rising edge

}


/**************************************************************
 *  Name                 : main
 *  Description          : main program, initialize cpu and run aplication
 *  Parameters           :  none
 *  Return               :  none
 *  Critical/explanation :  No
 **************************************************************/
void main(void)
{

initializeADC();
    cpu_drv_init();

    mw_schm_schInit();

    mw_schm_schExec();

}